const path = require("path");
// 基础路径 注意发布之前要先修改这里
const publicPath = "/";
function resolve(dir) {
  return path.join(__dirname, dir);
}

// 设置不参与构建的库
const externals = {};
module.exports = {
  publicPath,
  lintOnSave: false,
  productionSourceMap: false, // 如果你不需要生产环境的source map, 可以将其设置为false 以加速生产环境构建
  devServer: {
    proxy: {
      "/data": {
        // target: "http://192.168.20.113:8007", // http://192.168.20.119:8004 http://fai365.com:30150/
        // target: "http://192.168.20.119:9086", // http://192.168.20.119:8004 http://fai365.com:30150/
        target: "http://smartai.com:7011", // http://192.168.20.119:8004 http://fai365.com:30150/

        ws: true,
        changeOrigin: true,
      },
      "/httpImage/": {
        // target: "http://192.168.20.113:8007", // http://192.168.20.119:8004 http://fai365.com:30150/
        // target: "http://192.168.20.119:9086", // http://192.168.20.119:8004 http://fai365.com:30150/
        target: "http://smartai.com:7011", // http://192.168.20.119:8004 http://fai365.com:30150/

        ws: true,
        changeOrigin: true,
      },
    },
  },
  transpileDependencies: [
    // 兼容IE11浏览器(兼容npm包和cnpm包)
    "crypto-js",
    "sockjs-client",
  ],
  configureWebpack: (config) => {
    const configNew = {};
    if (process.env.NODE_ENV === "production") {
      configNew.externals = externals;
      configNew.plugins = [];
    } else if (process.env.NODE_ENV === "development") {
      console.log("development", config);
    }
    return configNew;
  },
  chainWebpack(config) {
    // 设置svg导入
    /**
     * 将svg图片以雪碧图的方式在项目中加载
     */
    config.module.rule("svg").exclude.add(resolve("src/assets/icons")).end();
    config.module
      .rule("icons")
      .test(/\.svg$/)
      .include.add(resolve("src/assets/icons")) // svg所在路径
      .end()
      .use("svg-sprite-loader")
      .loader("svg-sprite-loader")
      .options({
        // 参数配置
        symbolId: "icon-[name]",
      });
  },
  css: {
    loaderOptions: {
      // 设置 scss 公用变量文件
      sass: {
        additionalData: `@import "@/assets/style/variable.scss";`,
      },
      // postcss: {
      //   postcssOptions: {
      //     plugins: [
      //       require("postcss-pxtorem")({
      //         rootValue: 192.0,
      //         propList: ["*"],
      //       }),
      //     ],
      //   },
      // },
    },
  },
};
